package com.miniprogram.common.utils;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class JsonUtils {
    private static final ObjectMapper JSON = new ObjectMapper();

    static {
        JSON.setSerializationInclusion(Include.NON_NULL);
        JSON.configure(SerializationFeature.INDENT_OUTPUT, Boolean.TRUE);
    }

    public static String toJson(Object obj) {
        try {
            return JSON.writeValueAsString(obj);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        return null;
    }

//    public static List<OrderGoodsDto> toGoodsInfo(List<JSONObject> json) {
//        log.info(json.toString());
//        List<OrderGoodsDto> resp = new ArrayList<>();
//        json.forEach(key -> resp.add(JSONUtil.toBean(key, OrderGoodsDto.class)));
//        log.info(resp.toString());
//        return resp;
//    }

//    public static List<OrderGoodsDto> toGoodsInfo(String json) {
//        List<OrderGoodsDto> resp = com.alibaba.fastjson.JSON.parseArray(json, OrderGoodsDto.class);
//        return resp;
//    }

}